<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\UserVerifyInfo>
 */
class UserVerifyInfoFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $i = mt_rand(0, 9);
        $companyNamePrefix = ["甲", "乙", "丙", "丁", "戊", "己" ,"庚" , "辛", "壬"];
        $randUserId = mt_rand(4, 32);
        $idCard = $this->generateRandomIDNumber();
        $realName = fake()->name();
        $type = 1;
        $businessLicense = '';
        if ($i %2 == 0) {
            $businessLicense = $companyNamePrefix[$i] . '有限公司';
            $type = 2;
        }
        // 这里只能返回一维数组，不然就会报错，Illuminate\Database\Grammar::parameterize(): Argument #1 ($values) must be of type array, string given,
        return [
            'user_id' => $randUserId,
            'id_card' => $idCard,
            'real_name' => $realName,
            'business_license' => $businessLicense,
            'type' => $type,
        ];
    }

    public function generateRandomIDNumber(): string
    {
        $provinceCode = str_pad(rand(1, 99), 2, '0', STR_PAD_LEFT);
        $birthDate = date('Ymd', mt_rand(strtotime('1950-01-01'), strtotime('2000-12-31')));
        $sequence = str_pad(rand(1, 999), 3, '0', STR_PAD_LEFT);
        $checksum = rand(0, 9);
        $idNumber = $provinceCode . $birthDate . $sequence . $checksum;
        return $idNumber;
    }
}
